package queue;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:墨琦
 * Data:2023-04-16
 * Time:16:11
 */
public class CirculateQueue {
       int[] elem;
       int rear;
       int front;
       public CirculateQueue(int num)
       {
              this.elem=new int[num];
       }
       public boolean isFull()
       {
         return ( rear + 1 ) %elem.length == front;
       }
       public boolean isEmpty()
       {
              return rear==front;
       }
       public boolean enqueue(int num)
       {
              if(isFull())
              {
                 return false;
              }
              elem[rear]=num;
              rear = (rear+1)% elem.length;
              return true;
       }
       public boolean outqueue()
       {
              if(isEmpty())
              {
                     return false;
              }
              front = (front+1)% elem.length;
              return true;
       }
       public int getFront()
       {
              if(isEmpty())
              {
                     return -1;
              }
              return elem[front];
       }

       public int getRear()
       {
              if(isEmpty()) {
                     return -1;
              }
              int index = (rear == 0) ? elem.length-1 : rear-1;
              return elem[index];
       }
}
